import RiskWarnApi from './service.js'

export default {
  data () {
    return {
      loading: false,
      Ids: '',
      firstParentCompanys: [], // 上级公司
      companys: [], // 客户
      servers: [], // 客服
      CooperateTypeArr: [], // 合作类型
      StatusArr: [], // 合作状态
      RenewalStatusArr: [{value:'0', label:'待续约'},{value:'1', label:'已续约'}], // 续约状态
      RetireStatusArr: [{value:'0', label:'待退休'},{value:'1', label:'已退休'}], // 退休状态
      RenewalMonthArr: [], // 到期时间
      RetireMonthArr: [], // 离退休时间
      OnBoardingMonthArr: [], // 入职时间
      EmployeeTypeArr: [],
      BeHiringNameArr: [{ value: '在职', label: '在职' }, { value: '离职', label: '离职' }, { value: '离职未报停', label: '离职未报停', isDisabled: true }],
      searchData: {
        ParentCompanyName: '', // 上级公司id
        CompanyId: '', // 客户id
        CustomerName: '', 
        ServerId: '', // 客服id
        ServerName: '', // 客服名称
        Name: '', // 姓名
        IdCardNo: '', // 	身份证号码
        CooperateType: '', // 合作类型
        Status: '1', // 合作状态
        EmployeeType: '', // 用工形式
        BeHiringName: '在职', // 在职状态
        Sex: '',
        RenewalStatus: '0', // 续约状态：0待续约，1已续约
        RenewalMonth:'', // 到期时间
        RetireStatus: '', // 退休状态：0待退休,1已退休
        RetireMonth: '', // 离退休时间
        OnBoardingMonth: '', // 入职(月)
        PageIndex: 1,
        PageSize: 10,
      },
      totalRows: 0,
      tableData: [],
    }
  },
  mounted () {
    
    this.getServers()
    this.getEnum()
    this.getEmployeeTypeArr()
    this.getRenewalMonthArr()
    this.getRetireMonthArr()
  },
  computed: {
    actionArr () {
      let arr = this.$store.state.user.actionAccess.map(item => {
        return item.code
      })
      return arr
    },
    hasFind () {
      return this.actionArr.indexOf('Find') > -1
    },
    hasExport () {
      return this.actionArr.indexOf('Export') > -1
    }
  },
  methods: {
    // 获取客服
    /**
     * server所属客服下拉数据
     */
    getServers () {
      RiskWarnApi.postServers({
        pageIndex: 1,
        pageSize: 1000
      }).then(res => {
        this.servers = res.data[0].items
      })
    },
    // 获取上级公司
    getFirstParentCompanys (type) {
      RiskWarnApi.GetParentCompanys({
        type: type
      }).then(res => {
        if (res.data.success) {
          this.firstParentCompanys = res.data.data
        } else {
          this.$Message.error(res.data.message)
        }
      })
    },
    /**
     * 数据字典
     */
    getEnum () {
      let groupNames = 'customer.type,EmploymentForm,customer.status'
      RiskWarnApi.getEnum({
        groupName: groupNames
      }).then((res) => {
        this.CooperateTypeArr = this.getItems(res.data, 'customer.type')
        this.StatusArr = this.getItems(res.data, 'customer.status')
      })
    },
    getItems (arr, key) {
      let object = arr.find((item) => {
        return item.group === key
      })
      return object.items
    },
    getEmployeeTypeArr () {
      RiskWarnApi.getSelectValueList({ type: 'EmploymentForm' }).then(res => {
        this.EmployeeTypeArr = res.data.data
      })
    },
    getRenewalMonthArr () {
      RiskWarnApi.getSelectValueList({ type: 'RiskWarnRenewalMonth' }).then(res => {
        this.RenewalMonthArr = res.data.data
      })
    },
    // 退休时间
    getRetireMonthArr () {
      RiskWarnApi.getSelectValueList({ type: 'RiskWarnRetireMonth' }).then(res => {
        this.RetireMonthArr = res.data.data
      })
    },
    getOnBoardingMonthArr () {
      RiskWarnApi.getSelectValueList({ type: 'RiskWarnOnBoardingMonth' }).then(res => {
        this.OnBoardingMonthArr = res.data.data
      })
    },
    ParentCompanyChange (val) {
      console.log(val)
      // RiskWarnApi.GetAllChildCompanys({
      //   companyGuid: val
      // }).then(res => {
      //   this.searchData
      // })
    },
    // 表格change
    onSelectChange (val) {
      console.log(val)
      let arr = val.map(item => {
        return item.id
      })
      if (arr.length > 0) {
        this.Ids = arr.join(',')
      } else {
        this.Ids = ''
      }
    },
    /**
     * 分页
     * @param {Number} val pageIndex
     */
    onChangePage (val) {
      this.searchData.PageIndex = val
      this.getListData()
    },
    /**
     * 分页页码变动
     */
    onpageSizeChange (val) {
      this.searchData.PageIndex = 1
      this.searchData.PageSize = val
      this.getListData()
    },
    
  }
}